package com.java_foundation.thread_demo.test_7;

/**
 * @program: java_foundation
 * @description: notify() 与notifyAll() 方法示例
 * @author: xiongbangwen <Email>xiongbangwen@163.com</Email>
 * @create: 2020-06-21 17:36
 **/
public class NotifyDemo {
    private static volatile Object resourceA = new Object();
    Thread threadA = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized(resourceA){
                System.out.println("线程A获取resourceA的监视器锁");
                try {
                    System.out.println("线程A开始等待");
                    resourceA.wait();
                    System.out.println("线程A结束等待");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    Thread threadB = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized(resourceA){
                System.out.println("线程B获取resourceA的监视器锁");
                try {
                    System.out.println("线程B开始等待");
                    resourceA.wait();
                    System.out.println("线程B结束等待");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    });
    Thread threadC = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized(resourceA){
                System.out.println("C线程唤醒资源A");
//                resourceA.notify();
                resourceA.notifyAll();
            }
        }
    });
}
